//品牌控制层
app.controller('brandController', function ($scope,$controller,brandService) {      //读取列表数据绑定到表单中

    $controller('baseController',{$scope:$scope});//继承

    //查询品牌列表
    $scope.findAll = function () {
        brandService.findAll().success(
            function (response) {
                $scope.list = response;
            }
        )
    }

    //分页
    $scope.findPage = function (page, rows) {
        brandService.findPage(page,rows).success(
            function (response) {
                //显示当前页数据
                $scope.list = response.rows;
                //更新总记录数
                $scope.paginationConf.totalItems = response.total;
            }
        )
    }

    //新增
    $scope.save = function () {
        var obj = null;

        if ($scope.entity.id != null) {
            //如果有id则进行修改操作
            obj = brandService.update($scope.entity);
        }else{
            obj = brandService.add($scope.entity);
        }

        obj.success(
            function (response) {
                if (response.success) {
                    //成功刷新
                    $scope.reloadList();
                } else {
                    alert(response.message);
                }
            }
        );
    }

    //查询实体
    $scope.findOne = function (id) {
        brandService.findOne(id).success(
            function (response) {
                $scope.entity = response;
            }
        )
    }

    //批量删除
    $scope.del = function () {
        if (confirm('确定要删除吗？')) {
            brandService.delete($scope.selectIds).success(
                function (response) {
                    if (response.success) {
                        //成功刷新列表
                        $scope.reloadList();
                    } else {
                        alert(response.message);
                    }
                }
            )
        }
    }

    $scope.searchEntity = {};
    //条件查询
    $scope.search = function (page,rows) {
        brandService.search(page,rows,$scope.searchEntity).success(
            function (response) {
                //显示当前页数据
                $scope.list = response.rows;
                //更新总记录数
                $scope.paginationConf.totalItems = response.total;
            }
        )
    }

});
